package leetcode100;

// TODO 脑筋急转弯 | 一次遍历 【-】 买卖股票的最佳时机
// TODO https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/solution/by-jyd-cu90/

class lc100_0121 {
    public int maxProfit(int[] prices) {
        int minBuy  = prices[0];
        int maxPro = 0;

        for (int i=1; i<prices.length; i++) {
            minBuy = Math.min(minBuy, prices[i]);
            maxPro = Math.max(maxPro, prices[i] - minBuy);
        }

        return maxPro;
    }
}